// 引入用来发送请求的方法
import { request } from "../../request/index.js"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods:[],
    isFocus:false,
    inpValue:""
  },
  TimeId:-1,
  handleInput(e){
    const {value}=e.detail
    if(!value.trim()){
      this.setData({
        goods:[],
        isFocus:false
      })
      return
    }
    this.setData({
      isFocus:true
    })
    clearTimeout(this.TimeId)
    this.TimeId=setTimeout(() => {
      this.qsearch(value)
    }, 1000);
    
  },

  // 获取数据

  async qsearch(query){
    const res=await request({url:"/goods/qsearch",data:{query}})
    this.setData({
      goods:res
    })
  },
  // 取消按钮
  handleCancel(){
    this.setData({
      inpValue:'',
      goods:[],
      isFocus:false
    })
  }
  
})